

    //品牌荣誉
    var brandReput ={
        beginYear:0,//开始年份
        endYear:0,//结束年份
        nowYear :0,//当前选择年份
        liWidth: 190,//每次位移距离
        leftLi : 0,//左移位置
    };


    /**
     * 根据年限获取所有的内容
     * @param year
     */
    brandReput.initContent = function( year ){
        var $brandDiv = $(".brand-honors");
        $brandDiv.find('.brand-honor').remove();
        $brandDiv.find('.brand-honor').remove();
        $brandDiv.find('.more-btn').remove();

        brandReput.nowYear = year;
        //当前选中年份大于最小年份就显示右边建投
        if( parseInt(brandReput.nowYear) > brandReput.beginYear ){
            $('.brand-times #time-next').css("display","block");
        }else{
            $('.brand-times #time-next').css("display","none");
        }
        //计算ul的left如果是负值就要有左移
        if( parseInt($('.brand-times ul').css('left'))<0){
            $('.brand-times #time-prev').css("display","block");
        }else{
            $('.brand-times #time-prev').css("display","none");
        }
        //获取时间发布的时间轴
        $.ajax({
            async: false,
            url: '/brand/findBrandReput',
            data:{"year":year},
            success: function (result) {
                if (result && result.code == 200) {
                    if (result.data != '') {
                        var brandList = result.data;
                        var $brandHisDiv = '';
                        var maxShowItem = 8;
                        //循环获取品牌信息
                        $.each(brandList,function(key,brand){
                            if( key < maxShowItem) {
                                $brandHisDiv += '<div class="brand-honor">';
                            }else{
                                $brandHisDiv += '<div class="brand-honor item-hide" >';
                            }
                            $brandHisDiv += '<img src="' + brand.url + '" alt="" class="imgItem">';
                            $brandHisDiv += '<span title="' + brand.brandName + '">' + brand.brandName + '</span></div>';
                        });
                        $brandDiv.find('.brand-honor').remove();
                        $brandDiv.append($brandHisDiv);
                        if( brandList.length >= maxShowItem ){
                            $brandDiv.append('<button class="more-btn">MORE</button>');
                        }


                        $('.more-btn').on('click',function(){
                            if($('.item-hide').length > 0){
                                $('.item-hide').each(function(index){
                                    if( index < maxShowItem )
                                        $(this).removeClass("item-hide");
                                });

                                //当没有需要加载的数据时
                                if($('.item-hide').length == 0){
                                    $(this).text("NONE");
                                }
                            }
                        });

                    }
                }else{
                    $brandDiv.find('.brand-honor').remove();
                    $brandDiv.append('<div class="brand-honor"><span>没有数据!</span></div>');
                }
            }
        });
    };
    /**
     * 初始化
     * **/
    brandReput.init = function(){
        //获取时间发布的时间轴
        $.ajax({
            async: false,
            url: '/brand/findBrandReputYear',
            success: function (result) {
                if (result && result.code == 200) {
                    if (result.data != '') {
                       var beginYear =  result.data.beginYear;//开始时间
                        var endYear =  result.data.endYear;//结束时间
                        brandReput.beginYear = beginYear;
                        brandReput.endYear = endYear;
                        brandReput.nowYear = endYear;
                        var nowYear = endYear;
                        var $timesDiv = $('.brand-times ul');

                        //构建所有的年份时间
                        var $timeLi ='';
                        do{
                            if( nowYear == endYear )
                                $timeLi+='<li class="time-af" name="'+endYear+'">'+endYear+'年</li>';
                            if( nowYear != endYear )
                                $timeLi+='<li name="'+endYear+'">'+endYear+'年</li>';
                            endYear --;
                        }while (beginYear<=endYear);
                        //删除原有的
                        $timesDiv.find('li').remove();
                        $timesDiv.append($timeLi);//重新获取最新的时间

                        brandReput.initContent(nowYear);

                        //绑定事件
                        $('.brand-times ul li').on('click',function(e){
                            $('.brand-times ul li').removeClass("time-af");
                            $(this).addClass("time-af");
                            var selYear = $(this).attr('name');
                            //移动时间轴
                            //brandReput.moveLi( (parseInt( selYear ) - parseInt(brandReput.nowYear)) );

                            brandReput.initContent( $(this).attr('name') );


                        });

                        //绑定左移年份
                        $('.brand-times #time-prev').on('click',function(e){
                            var nowYear = parseInt(brandReput.nowYear) +1;
                            $('.brand-times ul li').each(function(){
                                if( $(this).attr('name') == nowYear){
                                    $(this).addClass("time-af");
                                }else{
                                    $(this).removeClass("time-af");
                                }
                            });

                            brandReput.moveLi(1);
                            brandReput.initContent( nowYear );

                        });

                        //绑定右移年份
                        $('.brand-times #time-next').on('click',function(e){
                            var nowYear = brandReput.nowYear - 1;
                            $('.brand-times ul li').each(function(){
                                if( $(this).attr('name') == nowYear){
                                    $(this).addClass("time-af");
                                }else{
                                    $(this).removeClass("time-af");
                                }
                            });
                            //左移一个位置 li
                            brandReput.moveLi(-1);
                            brandReput.initContent( nowYear );
                        });

                    }
                }
            },
            error: function () {
                layer.alert('服务器出错啦！', {icon: 2, title: '错误'});
            }
        });
    };
    brandReput.moveLi = function( leftSum ){
        //左移一个位置 li
        var leftWidth = leftSum*brandReput.liWidth;//计算位移距离
        var leftPost = $('.brand-times ul').css('left');//当前位置
        $('.brand-times ul').css('left',parseInt(leftPost)+parseInt(leftWidth)+'px');
    };

$(function(){


    //初始化
    brandReput.init();
    header.selLiCss("brand");
    //面包屑名称
    $("#menu-ico span").html("•&nbsp;&nbsp;品牌&nbsp;&nbsp;•&nbsp;&nbsp;品牌荣誉");
});